home *** CD-ROM | disk | FTP | other *** search
/ CD Exchange / CD Exchange - Volume 1.iso / education / gravity-well / gw-include.h < prev    next >
Text File  |  1989-09-24  |  17KB  |  480 lines

  1. /*
  2.       GW-Include.h
  3.       Shared code include for Gravity-Well
  4.       Gary Teachout
  5.       Copyright   July  1989
  6. */
  7.  
  8.  
  9.  #include <exec/types.h>
  10.  #include <exec/memory.h>
  11.  #include <libraries/dos.h>
  12.  #include <libraries/dosextens.h>
  13.  #include <intuition/intuition.h>
  14.  #include <graphics/gfxmacros.h>
  15.  #include <string.h>
  16.  #include <math.h>
  17.  #include <float.h>
  18.  
  19.  
  20.  #define LINEPEN     1        /*    pen colors  */
  21.  #define DOTPEN      3
  22.  #define BPEN        2
  23.  #define DPEN        0
  24.  #define MFPEN       0
  25.  #define MBPEN       2
  26.  
  27.  #define NEWCENTER      1     /*    awaiting    */
  28.  #define NEWPOSITION    2
  29.  #define NEWVELOCITY    3
  30.  #define NEWMASS        4
  31.  #define NEWCREATE      5
  32.  
  33.  
  34.  struct dv        /*    double   3 - d   vector    */
  35.       { double  x , y , z  ; }  ;
  36.  
  37.  struct obv       /*    orthogonal  basis vectors  */
  38.       { struct dv  i , j , k  ; }  ;
  39.  
  40.  struct object    /*    data for each body   */
  41.  {
  42.    struct dv      position ,
  43.                   velocity ,
  44.                   oldpos ,
  45.                   startpos ,
  46.                   startvel  ;
  47.    double         mass ,
  48.                   startmass ,
  49.                   radius  ;
  50.    short          flags ,
  51.                   collision  ;
  52.    char           name[ 68 ]  ;
  53.  }  ;
  54.  
  55.  struct filedata  /*    data for the entire simulation   */
  56.  {                
  57.    char           tag[ 16 ]  ;
  58.    struct object  objects[ 20 ]  ;
  59.    struct obv     viewbasis ,
  60.                   unviewbasis  ;
  61.    struct dv      viewoffset  ;
  62.    double         elapsedtime ,
  63.                   timestep ,
  64.                   scale ,
  65.                   magic  ;
  66.    USHORT         stopflag ,
  67.                   awaiting ,
  68.                   trailson ,
  69.                   objectnum ,
  70.                   follow  ;
  71.    char           filecomment1[ 66 ] ,
  72.                   filecomment2[ 66 ]  ;
  73.  }  ;
  74.  
  75.  struct menubox   /*    text menu items   */
  76.  {
  77.    struct MenuItem      item  ;
  78.    struct IntuiText     text  ;
  79.  }  ;
  80.  
  81.  
  82. /*    System prototypes    */
  83.  
  84.  char                   *AllocMem()  ;
  85.  struct Screen          *OpenScreen()  ;
  86.  struct Window          *OpenWindow()  ;
  87.  struct IntuiMessage    *GetMsg()  ;
  88.  struct FileHandle      *Open()  ;
  89.  struct TextFont        *OpenDiskFont()  ;
  90.  
  91. /*    GW-Main prototypes   */
  92.  
  93.  void main( void )  ;
  94.  void takestep( double )  ;
  95.  
  96. /*    GW-Interface prototypes    */
  97.  
  98.  void startup( void )  ;
  99.  void cleanup( void )  ;
  100.  void openmainview( void )  ;
  101.  void opentopview( void )  ;
  102.  void openrightview( void )  ;
  103.  void openviewcontrol( void )  ;
  104.  void pixel( struct Window * , double , double )  ;
  105.  void blankwindow( struct Window * )  ;
  106.  void line( struct Window * , double , double , double , double )  ;
  107.  void linelong( struct Window * , long , long , long , long )  ;
  108.  void interface( void )  ;
  109.  void readmes( void )  ;
  110.  void handelmenu( void )  ;
  111.  void stoploop( void )  ;
  112.  void resetdisplay( void )  ;
  113.  void screentitle( long )  ;
  114.  void setupdisplay( struct Window * )  ;
  115.  void set( void )  ;
  116.  void create( void )  ;
  117.  void setstrings( void )  ;
  118.  void deleteobject( long )  ;
  119.  void endtrail( long , long )  ;
  120.  void updatedisplay( void )  ;
  121.  
  122. /*    GW-Vectors prototypes   */
  123.  
  124.  void rotatedv( struct dv * , struct dv * , double * , double * )  ;
  125.  void rotatedvpair10( struct dv * , struct dv * )  ;
  126.  void adddv( struct dv * , struct dv * , struct dv * )  ;
  127.  void subdv( struct dv * , struct dv * , struct dv * )  ;
  128.  void scaledv( struct dv * , double * , struct dv * )  ;
  129.  void dotdv( struct dv * , struct dv * , double * )  ;
  130.  void crossdv( struct dv * , struct dv * , struct dv * )  ;
  131.  void magdv( struct dv * , double * )  ;
  132.  void basis( struct dv * , struct obv * , struct dv * )  ;
  133.  
  134.  
  135. /*    Global Data    */
  136. /*    all but one file must be compiled with the -x option  */
  137.  
  138.  struct IntuitionBase      *IntuitionBase  ;
  139.  struct GfxBase            *GfxBase  ;
  140.  struct Library            *DiskfontBase  ;
  141.  
  142.  struct IntuiMessage       *mes  ;
  143.  struct Screen             *screen  ;
  144.  struct Window             *control ,     /* renamed the Data window   */
  145.                            *viewcontrol ,
  146.                            *mainview ,
  147.                            *topview ,
  148.                            *rightview  ;
  149.  
  150.  struct TextAttr           stext = { "topaz.font" , 8 , 0 , 0 }  ;
  151.  struct TextAttr           rtext = { "topaz.font" , 11 , 0 , 0 }  ;
  152.  struct TextFont           *rfont  ;
  153.  
  154.  ULONG                     class  ;
  155.  USHORT                    code  ;
  156.  short                     mousex ,
  157.                            mousey  ;
  158.  
  159.  struct Gadget             *iadd  ;
  160.  
  161.  char    *titletext[ 6 ] =
  162.  {
  163.    "  Gravity Well" ,
  164.    "  Gravity Well     Awating New Center Point" ,
  165.    "  Gravity Well     Awating New Position" ,
  166.    "  Gravity Well     Awating New Velocity" ,
  167.    "  Gravity Well     Awating New Mass" ,
  168.    "  Gravity Well     Create Mode" 
  169.  }  ;
  170.  
  171.  char    ettext[ 33 ]  ;
  172.  
  173.  char    numbertext[] =
  174.    "  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20  "  ;
  175.  
  176.  char    *controlgtext[ 11 ] =
  177.  {
  178.    "Position" , "Velocity" , "Mass    " ,
  179.    "Delete  " , "Zero  M " , "Start   " ,
  180.    "  Load  " , "  Save  " , "  New   " ,
  181.    " Create " , " Enter  "
  182.  }  ;
  183.  
  184.  char    *conlabel[ 10 ] =
  185.  {
  186.    "File Name:" ,
  187.    "Comment:" ,
  188.    "" ,
  189.    "Name:" ,
  190.    "Time Step:" ,
  191.    "Magic:" ,
  192.    "Mass:" ,
  193.    "Radius:" ,
  194.    "Start Position:" ,
  195.    "Start Velocity:"
  196.  }  ;
  197.  
  198.  short   conlabellength[ 10 ] =
  199.    {  10 , 8 , 0 , 5 , 10 , 6 , 5 , 7 , 15 , 15  }  ;
  200.  
  201.  short clut[ 4 ][ 3 ] =    /*    screen colors  */
  202.  {
  203.    { 0 , 0 , 0 } ,
  204.    { 15 , 0 , 0 } ,
  205.    { 10 , 8 , 0 } ,
  206.    { 15 , 15 , 15 }
  207.  }  ;
  208.  
  209.  struct  NewScreen   ns =
  210.  {
  211.    0 , 0 , 640 , 400 , 2 , DPEN , BPEN , HIRES | LACE ,
  212.    CUSTOMSCREEN , NULL , "  Gravity Well" , NULL , NULL
  213.  }  ;
  214.  
  215.  struct  NewWindow
  216.    controlnw =       /*    the Data window   */
  217.    {
  218.       0 , 12 , 640 , 388 , DPEN , BPEN , MENUPICK | GADGETUP ,
  219.       WINDOWDEPTH
  220.       | SMART_REFRESH | ACTIVATE ,
  221.       NULL , NULL , "  Data  " , 
  222.       NULL , NULL , 0 , 0 , 0 , 0 , CUSTOMSCREEN
  223.    } ,
  224.    viewcontrolnw =
  225.    {
  226.       490 , 0 , 100 , 173 , DPEN , BPEN , CLOSEWINDOW | MENUPICK | GADGETUP ,
  227.       WINDOWCLOSE | WINDOWDRAG | WINDOWDEPTH 
  228.       | SMART_REFRESH ,
  229.       NULL , NULL , "VC " , 
  230.       NULL , NULL , 0 , 0 , 0 , 0 , CUSTOMSCREEN
  231.    } ,
  232.    mainviewnw =
  233.    {
  234.       80 , 92 , 460 , 308 , DPEN , BPEN , 
  235.       CLOSEWINDOW | NEWSIZE | MENUPICK | MOUSEBUTTONS ,
  236.       WINDOWCLOSE | WINDOWDRAG | WINDOWSIZING | WINDOWDEPTH 
  237.       | SMART_REFRESH ,
  238.       NULL , NULL , " Main View  " , 
  239.       NULL , NULL , 100 , 80 , 640 , 400 , CUSTOMSCREEN
  240.    } ,
  241.    topviewnw =
  242.    {
  243.       80 , 12 , 460 , 80 , DPEN , BPEN ,
  244.       CLOSEWINDOW | NEWSIZE | MENUPICK | MOUSEBUTTONS ,
  245.       WINDOWCLOSE | WINDOWDRAG | WINDOWSIZING | WINDOWDEPTH 
  246.       | SMART_REFRESH ,
  247.       NULL , NULL , " Top View  " , 
  248.       NULL , NULL , 100 , 80 , 640 , 400 , CUSTOMSCREEN
  249.    } ,
  250.    rightviewnw =
  251.    {
  252.       540 , 92 , 100 , 308 , DPEN , BPEN ,
  253.       CLOSEWINDOW | NEWSIZE | MENUPICK | MOUSEBUTTONS ,
  254.       WINDOWCLOSE | WINDOWDRAG | WINDOWSIZING | WINDOWDEPTH 
  255.       | SMART_REFRESH ,
  256.       NULL , NULL , " Right View  " ,
  257.       NULL , NULL , 100 , 80 , 640 , 400 , CUSTOMSCREEN
  258.    }  ;
  259.  
  260.  struct Menu menustrip[ 3 ] =    /* all windows share this menu strip   */
  261.  {
  262.    {  NULL , 1   , 0 , 120 , 10 , MENUENABLED , " QUIT" , NULL } ,
  263.    {  NULL , 121 , 0 , 120 , 10 , MENUENABLED , " Open Window" , NULL } ,
  264.    {  NULL , 241 , 0 , 120 , 10 , MENUENABLED , " Control" , NULL } 
  265.  }  ;
  266.  
  267.  struct menubox
  268.    menu0[ 1 ] =
  269.    {
  270.       {
  271.          {  NULL , 0 , 0 , 130 , 14 , ITEMTEXT | ITEMENABLED | HIGHCOMP ,
  272.             0 , NULL , NULL , 0 , NULL , 0  } ,
  273.          {  MFPEN , MBPEN , JAM1 , 15 , 2 , NULL , "QUIT" , NULL  }
  274.       }
  275.    } ,
  276.    menu1[ 5 ] =
  277.    {
  278.       {
  279.          {  NULL , 0 , 0 , 130 , 14 , ITEMTEXT | ITEMENABLED | HIGHCOMP ,
  280.             0 , NULL , NULL , 0 , NULL , 0  } ,
  281.          {  MFPEN , MBPEN , JAM1 , 15 , 2 , NULL , "Main View" , NULL  }
  282.       } ,
  283.       {
  284.          {  NULL , 0 , 14 , 130 , 14 , ITEMTEXT | ITEMENABLED | HIGHCOMP ,
  285.             0 , NULL , NULL , 0 , NULL , 0  } ,
  286.          {  MFPEN , MBPEN , JAM1 , 15 , 2 , NULL , "Top View" , NULL  }
  287.       } ,
  288.       {
  289.          {  NULL , 0 , 28 , 130 , 14 ,